<?php

namespace Common\Logic;

class ResLogic
{
    const SUC_CODE = 10000;
    const ERR_CODE = -10000;

    public function suc($msg = '成功', $data = array())
    {
        return $this->getRes(static::SUC_CODE, $msg, $data);
    }

    public function err($msg = '失败', $data = array())
    {
        return $this->getRes(static::ERR_CODE, $msg, $data);
    }

    public function isSuc($res)
    {
        return $res['Code'] == static::SUC_CODE ? true : false;
    }

    public function isErr($res)
    {
        return !$this->isSuc($res);
    }

    public function getRes($code, $msg, $data = null)
    {
        $res = array(
            "Code" => $code,
            "Message" => $msg
        );
        if ($data !== null) {
            $res['Result'] = $data;
        }
        return $res;
    }
}
